package com.huluobo.a2202mvvm_im_douyindemo.register;

import android.util.Log;
import android.widget.Toast;

import androidx.lifecycle.MutableLiveData;

import com.huluobo.a2202mvvm_im_douyindemo.login.LoginUserBean;
import com.huluobo.a2202mvvm_im_douyindemo.mvvmBase.BaseRepo;
import com.hyphenate.exceptions.HyphenateException;

/**
 * Created by LC on 2024/4/20.
 */
public class RegisterRepo extends BaseRepo {
    public void register(String username, String password, MutableLiveData<LoginUserBean> success,
                         MutableLiveData<Integer> failed) {
        new Thread(() -> {
            try {
                emClient.createAccount(username, password);
                success.postValue(new LoginUserBean(username, password));
            } catch (HyphenateException e) {
                failed.postValue(e.getErrorCode());
                if (e.getErrorCode() == 203) {
                    return;
                }
                throw new RuntimeException(e);
            }
        }).start();

    }
}
